<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>

<script>

  // 所谓promise封装: 
  // 就是通过new Promise包裹异步函数，通过resolve，reject，来获取异步函数的结果 
  function time () {
    return new Promise((resolve, reject) => {
      // 丢异步操作
      setTimeout(() => {
        resolve({ code: 200, msg: '操作成功' })
      }, 2000)
      // ajax异步操作(伪代码)
      // const xhr = new XMLHttpRequest()
      // xhr.open(xx, xx)
      // xhr.send(xx)
      // xhr.addEventListener('load', function() {
      //   resolve(xxx)
      // })
    })
  }
  time().then(res => {
    console.log(res)
  })




</script>
  
</body>
</html>